package com.boss.salary.controller;

import com.boss.api.dto.ApiResultDTO;
import com.boss.common.base.BasicinfoBaseController;
import com.boss.common.entity.PageDTO;
import com.boss.common.util.PageUtils;
import com.boss.framework.dto.PaginationDTO;
import com.boss.salary.entity.ReportByTheUnit;
import com.boss.salary.service.IReportByTheUnitService;
import org.apache.servicecomb.provider.rest.common.RestSchema;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.ws.rs.core.MediaType;
import java.util.HashMap;
import java.util.Map;

@RestSchema(schemaId = "ReportByTheUnitController")
@RestController
@RequestMapping(value = "/ReportByTheUnitController", produces = MediaType.APPLICATION_JSON)
public class ReportByTheUnitController extends BasicinfoBaseController {

    /**
     * 引入日志框架常量
     */
    private final static Logger logger = LoggerFactory.getLogger(ReportByTheUnitController.class);


    @Autowired
    private IReportByTheUnitService service;

    //获取应发工资  和  实发工资 单位名称
    @GetMapping("/queryUnitSubmitSituationQueryList")
    public ApiResultDTO queryUnitSubmitSituationQueryList(
            @RequestParam(value = "page") String page,
            @RequestParam(value = "limit") String limit,
            @RequestParam(value = "flag") String flag,
            @RequestParam(value = "agencyId") String agencyId,
            @RequestParam(value = "changesType") String changesType,
            @RequestParam(value = "personType") String personType,
            @RequestParam(value = "salaryType") String salaryType,
            //                        @RequestParam(value = "num") String num,
            // 前台报Required String parameter 'agencyId' is not present 不存在所需要的字符串id
            @RequestParam(value = "newId",required = false) String newId,
            @RequestParam(value = "agencyName") String agencyName
    ){
        try {
            PaginationDTO paginationDTO = PageUtils.buildPaginationDTOPage(page, limit);
            Map<String, Object> queryParam = new HashMap<>(1);
            queryParam.put("flag", flag);
            queryParam.put("agencyId", agencyId);
            queryParam.put("changesType", changesType);
            queryParam.put("personType", personType);
            queryParam.put("salaryType", salaryType);
            queryParam.put("agencyName", agencyName);
            queryParam.put("newId", newId);
            //queryParam.put("num", num);
            PageDTO<ReportByTheUnit> ReportByTheUnitPageDTO = service.queryunitSubmitSituationQueryList(paginationDTO, queryParam);
            return ApiResultDTO.success(ReportByTheUnitPageDTO,null);
        } catch (Exception e) {
            logger.error("获取工资数据发生异常", e);
            return ApiResultDTO.error(ERROR_RSCODE, "查询失败");
        }
    }


}
